package com.t11;


import java.util.*;

/**
 * Created by xuyiwei on 2018/7/23.
 */
public class ModifyArrayAsList {
    public static void main(String[] args) {
        Random random = new Random(47);
        Integer[] arr = {1,2,3,4,5,6,7,8};
        //这里在容器中创建了一个副本去执行的list
        List<Integer> list1 = new ArrayList< >(Arrays.asList(arr));
        Collections.shuffle(list1,random);
        System.out.println("list1: "+ list1);
        System.out.println("arr: "+  Arrays.toString(arr));

        //直接这样声明list的话，他就会使用底层数组作为物理实现，因此修改了list就相当于修改数组
        List<Integer> list2 = Arrays.asList(arr);
        Collections.shuffle(list2,random);
        System.out.println("list2: "+ list2);
        System.out.println("arr: "+ Arrays.toString(arr));
        /**
         *list1: [5, 4, 7, 1, 8, 2, 3, 6]
         arr: [1, 2, 3, 4, 5, 6, 7, 8]
         list2: [7, 3, 1, 5, 8, 2, 6, 4]
         arr: [7, 3, 1, 5, 8, 2, 6, 4]
         */
    }
}
